import React from 'react';
import filesaver from 'file-saver';
import { Button } from 'antd'
import { Workbook } from "@fortune-sheet/react";
import "@fortune-sheet/react/dist/index.css"

interface Props {}

function Excel(props:Props) {

    var handleDownOne =( )=>{
        //导出的逻辑：先发请求从服务器获取需要下载的数据，然后调用saveAs方法生成文件下载到本地
        filesaver.saveAs(new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"}),'abc.txt')
    }
    var handleDownTwo =( )=>{
        filesaver.saveAs("https://httpbin.org/image", "image.jpg");
    }

    return (
        <div className='excel' style={{height:800}}>
            <Button onClick={handleDownOne}>文本下载</Button>
            <Button onClick={handleDownTwo} style={{marginLeft:20}}>图片预览</Button>
            <Workbook data={[{ name: "Sheet1" }]} />
        </div>
    );
}

export default Excel;